<%@page contentType="application/json; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.text.*" %>
<%@ page import="org.team.sdsc.datamodel.*" %>


<%
     out.println("{ images: [");

     String trapName = request.getParameter("trapName");
     String event = request.getParameter("event");
     String raw = request.getParameter("raw");
     String path = request.getParameter("path");
    
     Network network = NetworkFactory.newInstance();
     CameraTrapPhoto photo = network.getCameraTrapPhoto(trapName, event, raw);
     Set<CameraTrapPhoto> gallery = new HashSet<CameraTrapPhoto>();
     if (photo != null) {
     	 gallery = network.getCameraTrapPhotoCluster(photo);
	 int k = 0;
	 for (CameraTrapPhoto tmp : gallery) {

	     CameraTrapPhotoType type = tmp.getType();
	     Person person = tmp.getTypeIdentifiedBy();
	     String typeName = "";
             if (type != null && person == null) {
	     	typeName = type.getName();
	     } 

	     if (k > 0) {
	        out.println(","); 
	     } else {
	        k++;
	     }
             out.println("{name:'"+tmp.getRawName()+"', "+
	     		 "size:500, "+
			 "lastmod:'"+tmp.getTakenTime()+"', "+
			 "annotated:"+(tmp.getType() != null)+", "+
			 "deleted: false, "+
			 "event: '"+event+"', "+
			 "trap: '"+trapName+"', "+
			 "type: '"+typeName+"', "+
			 "url:'image-repository"+path.replaceAll(raw, tmp.getRawName())+"'}");
	 }
     }
     network.close();

     out.println("]}");

%>



